﻿using System;
using System.Collections.Generic;
using System.Linq;
using Framework.Exceptions.RepositoryExceptions;
using Interfaces.Repositories;
using Interfaces.RepositoryModels.ExternalModels.FilterModels;


namespace SQLRepositories.FilterRepositories
{
    public class SectorsFilterRepository : EntityBaseRepository<SectorsFilterModel>, IFilterRepository<SectorsFilterModel>
    {
        public SectorsFilterRepository(IDBEconomicInformationServiceContext context) 
            : base(context)
        {}

        public void Create(SectorsFilterModel item)
        {
            Context.SectorsFilters.Add(item);
            Context.SaveChanges();

        }

        public SectorsFilterModel GetById(Guid id)
        {
            return Context.SectorsFilters.FirstOrDefault(x => x.Id.Equals(id));
        }

        public void Delete(Guid id)
        {
            var removedItem = Context.SectorsFilters.FirstOrDefault(x => x.Id.Equals(id));
            if(removedItem == null)
                throw new EntityNotFoundException("SectorsFilter");
            Context.SectorsFilters.Remove(removedItem);
            Context.SaveChanges();
        }

        public void Delete(SectorsFilterModel item)
        {
            Context.SectorsFilters.Remove(item);
            Context.SaveChanges();
        }

        public IEnumerable<SectorsFilterModel> GetAll()
        {
            return Context.SectorsFilters;
        }
    }
}
